//
//  MusicPlayerManager.m
//  HLMusicBox
//
//  Created by hulinhu on 2018/1/2.
//  Copyright © 2018年 hulinhu. All rights reserved.
//

#import "MusicPlayerManager.h"

@implementation MusicPlayerManager

#pragma mark Singleton Methods

+ (id)shareInstance {
    static dispatch_once_t onceToken = 0;
    __strong static id _shareManager = nil;
    dispatch_once(&onceToken, ^{
        _shareManager = [[self alloc] init];
    });
    return _shareManager;
}

-(void) setPlayItem: (NSString *)songURL {
    NSURL * url  = [NSURL URLWithString:songURL];
    _playItem = [[AVPlayerItem alloc] initWithURL:url];
}

-(void) setPlay {
    _play = [[AVPlayer alloc] initWithPlayerItem:_playItem];
}

-(void) startPlay {
    [_play play];
}

-(void) stopPlay {
    [_play pause];
}

-(void) play: (NSString *)songURL {
    [self setPlayItem:songURL];
    [self setPlay];
    [self startPlay];
}

@end
